home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ButtonBase.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  6.1 KB  |  315 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Canvas;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.awt.Event;
  9. import java.awt.Graphics;
  10. import java.awt.LayoutManager;
  11. import java.awt.Panel;
  12. import java.awt.Point;
  13. import symantec.beans.Beans;
  14. import symantec.itools.util.Timer;
  15.  
  16. public abstract class ButtonBase extends Canvas {
  17.    protected boolean pressed = false;
  18.    protected boolean released = true;
  19.    protected boolean inButton;
  20.    protected boolean notifyWhilePressed = false;
  21.    protected boolean showInfoTip = false;
  22.    protected boolean running = false;
  23.    protected boolean notified = false;
  24.    protected boolean showFocus;
  25.    protected boolean doInfoTip;
  26.    protected int bevel;
  27.    protected int notifyDelay;
  28.    protected int infoTipDelay;
  29.    protected int pressedAdjustment;
  30.    protected String infoTipText;
  31.    protected Color infoTipTextColor;
  32.    protected Timer notifyTimer = null;
  33.    protected Timer infoTipTimer = null;
  34.    protected int infoTipX;
  35.    protected int infoTipY;
  36.    protected LayoutManager infoTipLayoutManager;
  37.  
  38.    protected ButtonBase() {
  39.       this.infoTipTextColor = Color.black;
  40.       this.notifyDelay = 1000;
  41.       this.infoTipDelay = 1000;
  42.       this.bevel = 1;
  43.       this.pressedAdjustment = 0;
  44.       ((Component)this).resize(10, 10);
  45.    }
  46.  
  47.    public void setBevelHeight(int var1) {
  48.       try {
  49.          this.checkBevelSize(var1);
  50.       } catch (AWTException var2) {
  51.          System.err.println("Invalid Bevel Size " + var1);
  52.       }
  53.  
  54.       this.bevel = var1;
  55.       ((Component)this).invalidate();
  56.    }
  57.  
  58.    public int getBevelHeight() {
  59.       return this.bevel;
  60.    }
  61.  
  62.    public void setNotifyWhilePressed(boolean var1) {
  63.       this.notifyWhilePressed = var1;
  64.       if (this.notifyWhilePressed) {
  65.          this.notifyTimer = new Timer(this, this.notifyDelay, true, 1001);
  66.       } else {
  67.          if (this.notifyTimer != null) {
  68.             this.notifyTimer = null;
  69.          }
  70.  
  71.       }
  72.    }
  73.  
  74.    public boolean getNotifyWhilePressed() {
  75.       return this.notifyWhilePressed;
  76.    }
  77.  
  78.    public void setNotifyDelay(int var1) {
  79.       this.notifyDelay = var1;
  80.    }
  81.  
  82.    public int getNotifyDelay() {
  83.       return this.notifyDelay;
  84.    }
  85.  
  86.    public void setShowInfoTip(boolean var1) {
  87.       this.showInfoTip = var1;
  88.       if (this.showInfoTip) {
  89.          this.infoTipTimer = new Timer(this, this.notifyDelay, true, 1001);
  90.       } else {
  91.          if (this.infoTipTimer != null) {
  92.             this.infoTipTimer = null;
  93.          }
  94.  
  95.       }
  96.    }
  97.  
  98.    public boolean getShowInfoTip() {
  99.       return this.showInfoTip;
  100.    }
  101.  
  102.    public void setInfoTipDelay(int var1) {
  103.       this.infoTipDelay = var1;
  104.    }
  105.  
  106.    public int getInfoTipDelay() {
  107.       return this.infoTipDelay;
  108.    }
  109.  
  110.    public void setShowFocus(boolean var1) {
  111.       this.showFocus = var1;
  112.    }
  113.  
  114.    public boolean getShowFocus() {
  115.       return this.showFocus;
  116.    }
  117.  
  118.    public void setInfoTipText(String var1) {
  119.       this.infoTipText = var1;
  120.    }
  121.  
  122.    public String getInfoTipText() {
  123.       return this.infoTipText;
  124.    }
  125.  
  126.    public void setInfoTipTextColor(Color var1) {
  127.       this.infoTipTextColor = var1;
  128.    }
  129.  
  130.    public Color getInfoTipTextColor() {
  131.       return this.infoTipTextColor;
  132.    }
  133.  
  134.    public boolean mouseUp(Event var1, int var2, int var3) {
  135.       if (this.running) {
  136.          this.running = false;
  137.          this.notifyTimer.stop();
  138.       }
  139.  
  140.       if (this.pressed) {
  141.          this.pressed = false;
  142.          this.pressedAdjustment = 0;
  143.          if (!this.notifyWhilePressed || !this.notified) {
  144.             ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  145.          }
  146.       }
  147.  
  148.       this.released = true;
  149.       ((Component)this).repaint();
  150.       return true;
  151.    }
  152.  
  153.    public boolean mouseDown(Event var1, int var2, int var3) {
  154.       if (this.notifyWhilePressed && !this.running) {
  155.          this.running = true;
  156.          this.notifyTimer.start();
  157.       }
  158.  
  159.       this.pressed = true;
  160.       this.released = false;
  161.       this.pressedAdjustment = this.bevel;
  162.       ((Component)this).repaint();
  163.       return true;
  164.    }
  165.  
  166.    public boolean mouseEnter(Event var1, int var2, int var3) {
  167.       this.inButton = true;
  168.       if (this.showInfoTip) {
  169.          this.infoTipX = var2;
  170.          this.infoTipY = var3;
  171.          this.infoTipTimer.start();
  172.       }
  173.  
  174.       if (!this.released) {
  175.          this.mouseDown(var1, var2, var3);
  176.       }
  177.  
  178.       return true;
  179.    }
  180.  
  181.    public boolean mouseExit(Event var1, int var2, int var3) {
  182.       this.inButton = false;
  183.       if (this.showInfoTip) {
  184.          this.infoTipTimer.stop();
  185.          Panel var4 = InfoTipManager.getInfoTipPanel();
  186.          ((Component)var4).getParent().setLayout(this.infoTipLayoutManager);
  187.          ((Component)var4).hide();
  188.       }
  189.  
  190.       if (this.pressed) {
  191.          this.pressed = false;
  192.          this.pressedAdjustment = 0;
  193.       }
  194.  
  195.       return true;
  196.    }
  197.  
  198.    public boolean action(Event var1, Object var2) {
  199.       if (this.notifyWhilePressed && var1.target == this.notifyTimer && !Beans.isDesignTime()) {
  200.          ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  201.          return true;
  202.       } else if (this.showInfoTip && var1.target == this.infoTipTimer) {
  203.          this.doInfoTip = true;
  204.          ((Component)this).repaint();
  205.          this.infoTipTimer.stop();
  206.          return true;
  207.       } else {
  208.          return super.action(var1, var2);
  209.       }
  210.    }
  211.  
  212.    public void enable() {
  213.       if (!((Component)this).isEnabled()) {
  214.          super.enable();
  215.          this.pressed = false;
  216.          this.pressedAdjustment = 0;
  217.       }
  218.  
  219.       ((Component)this).repaint();
  220.    }
  221.  
  222.    public void disable() {
  223.       if (((Component)this).isEnabled()) {
  224.          super.disable();
  225.          if (this.notifyTimer != null) {
  226.             this.notifyTimer.stop();
  227.          }
  228.  
  229.          if (this.infoTipTimer != null) {
  230.             this.infoTipTimer.stop();
  231.          }
  232.  
  233.          this.pressed = false;
  234.          this.pressedAdjustment = 0;
  235.       }
  236.  
  237.       ((Component)this).repaint();
  238.    }
  239.  
  240.    public void update(Graphics var1) {
  241.       Dimension var2 = ((Component)this).size();
  242.       var1.clipRect(0, 0, var2.width, var2.height);
  243.       this.paint(var1);
  244.    }
  245.  
  246.    public void paint(Graphics var1) {
  247.       Dimension var2 = ((Component)this).size();
  248.       int var3 = var2.width;
  249.       int var4 = var2.height;
  250.       int var5 = this.bevel + 1;
  251.       int var6 = this.bevel + 1;
  252.       int var7 = var3 - 1;
  253.       int var8 = var4 - 1;
  254.       var1.setColor(Color.lightGray);
  255.       var1.fillRect(0, 0, var3, var4);
  256.       if (this.pressed) {
  257.          int var10000 = var5 + (this.bevel > 0 ? 2 : 1);
  258.          var1.setColor(Color.lightGray);
  259.  
  260.          for(int var9 = 1; var9 < this.bevel + 1; ++var9) {
  261.             var1.drawLine(var9, var8 - var9, var7 - var9, var8 - var9);
  262.             var1.drawLine(var7 - var9, var8 - var9, var7 - var9, var9);
  263.          }
  264.  
  265.          var1.setColor(Color.gray);
  266.  
  267.          for(int var10 = 1; var10 < this.bevel + 1; ++var10) {
  268.             var1.drawLine(var10, var8, var10, var10);
  269.             var1.drawLine(var10, var10, var7, var10);
  270.          }
  271.       } else {
  272.          var1.setColor(Color.white);
  273.  
  274.          for(int var11 = 1; var11 < this.bevel + 1; ++var11) {
  275.             var1.drawLine(var11, var8 - var11, var11, var11);
  276.             var1.drawLine(var11, var11, var7 - var11, var11);
  277.          }
  278.  
  279.          var1.setColor(Color.gray);
  280.  
  281.          for(int var12 = 1; var12 < this.bevel + 2; ++var12) {
  282.             var1.drawLine(var12, var8 - var12, var7 - var12, var8 - var12);
  283.             var1.drawLine(var7 - var12, var8 - var12, var7 - var12, var12);
  284.          }
  285.       }
  286.  
  287.       var1.setColor(Color.black);
  288.       var1.drawLine(1, 0, var3 - 2, 0);
  289.       var1.drawLine(0, 1, 0, var4 - 2);
  290.       var1.drawLine(1, var4 - 1, var3 - 2, var4 - 1);
  291.       var1.drawLine(var3 - 1, var4 - 2, var3 - 1, 1);
  292.       if (this.showInfoTip && this.doInfoTip) {
  293.          this.drawInfoTip();
  294.       }
  295.  
  296.    }
  297.  
  298.    protected void drawInfoTip() {
  299.       this.doInfoTip = false;
  300.       Point var2 = ((Component)this).location();
  301.       Panel var1 = InfoTipManager.getInfoTipPanel();
  302.       this.infoTipX += var2.x;
  303.       this.infoTipY += var2.y;
  304.       this.infoTipLayoutManager = ((Component)var1).getParent().getLayout();
  305.       InfoTipManager.draw(this.infoTipX, this.infoTipY, this.infoTipText, ((Component)this).getFontMetrics(((Component)this).getFont()), Color.yellow, Color.black);
  306.    }
  307.  
  308.    private void checkBevelSize(int var1) throws AWTException {
  309.       Dimension var2 = ((Component)this).size();
  310.       if (var1 < 0 || var1 >= var2.width / 2 || var1 >= var2.height / 2) {
  311.          throw new AWTException("invalid bevel size");
  312.       }
  313.    }
  314. }
  315.